import type { MarkType, NodeType } from "@rivet/model";
import type { PatchState } from "@rivet/state";

import { getMarkAttributes } from "./getMarkAttributes.ts";
import { getNodeAttributes } from "./getNodeAttributes.ts";
import { getSchemaTypeNameByName } from "./getSchemaTypeNameByName.ts";

//获取节点或标记的属性
export function getAttributes(
  state: PatchState,
  typeOrName: string | NodeType | MarkType,
): Record<string, any> {
  const schemaType = getSchemaTypeNameByName(
    typeof typeOrName === "string" ? typeOrName : typeOrName.name,
    state.schema,
  );

  if (schemaType === "node") {
    return getNodeAttributes(state, typeOrName as NodeType);
  }

  if (schemaType === "mark") {
    return getMarkAttributes(state, typeOrName as MarkType);
  }

  return {};
}
